import java.sql.* ;

class VendorDetails
{


CreateConnection cc ;

// Indexding of field a/c to database........

int id ;  // index-1
String name ; // index-2
String addr1 ; // index-3
String addr2 ; // index-4
String addr3 ; // index-5

String city ;  //index-6
String state ;  // index-7
String country ;  // index-8
String pincode ; // index-9
String ph1 ; // index-10
String ph2 ; // index-11
String email ; // index-12



	VendorDetails()
	{


	try{

		cc = new CreateConnection() ;

		}
		catch(Exception e)
	{}


	}



	VendorDetails(String[] s)  // string s consists of all details of vendor
	{


		id = Integer.parseInt(s[0]) ;
		name = s[1] ;
		addr1 = s[2] ;
		addr2 = s[3] ;
		addr3 = s[4] ;
		city = s[5] ;
		state = s[6] ;
		country = s[7] ;
		pincode = s[8] ;
		ph1 = s[9] ;
		ph2 = s[10] ;
		email = s[11] ;


/*
		System.out.println(id);
System.out.println(name);
System.out.println(addr1);
System.out.println(addr2);
System.out.println(addr3);
System.out.println(city);
System.out.println(state);
System.out.println(country);
System.out.println(pincode);
System.out.println(ph1);
System.out.println(ph2);
System.out.println(email);


*/


	try{

			cc = new CreateConnection() ;

			}
			catch(Exception e)
		{}




	}




	void insertDetailsInDB() throws Exception
	{




		String sql = "insert into vendor values (?,?,?,?,?,?,?,?,?,?,?,?)" ; // Each ? mark corresponds to a  index value.


		// get preparestatemnt

try{
		PreparedStatement p = cc.getStatement(sql) ;

		p.setInt(1,id );
		p.setString(2,name) ;
		p.setString(3,addr1) ;
		p.setString(4,addr2) ;
		p.setString(5,addr3) ;
		p.setString(6,city) ;
		p.setString(7,state) ;
		p.setString(8,country) ;
		p.setString(9,pincode) ;
		p.setString(10,ph1) ;
		p.setString(11,ph2) ;
		p.setString(12,email) ;


			int x = p.executeUpdate() ;

			if(x > 0)
			 System.out.println("Record Inserted Successfully");
}
catch(Exception e)
{
	System.out.println(e.getMessage());
}



	}





	void updateDetailsInDB( String[] s) throws Exception
		{


			id = Integer.parseInt(s[0]) ;
					name = s[1] ;
					addr1 = s[2] ;
					addr2 = s[3] ;
					addr3 = s[4] ;
					city = s[5] ;
					state = s[6] ;
					country = s[7] ;
					pincode = s[8] ;
					ph1 = s[9] ;
					ph2 = s[10] ;
					email = s[11] ;





			String sql = "update vendor set v_name = ?, v_addr1 =?, v_addr2 =?, v_addr3 =?, v_city = ?, v_state =?,v_country =?,v_pincode =?,v_ph1 = ?,	v_ph2 =?,v_email =? where v_id = ?" ;


			// get preparestatemnt

			PreparedStatement p = cc.getStatement(sql) ;

					p.setInt(12,id );
					p.setString(1,name) ;
					p.setString(2,addr1) ;
					p.setString(3,addr2) ;
					p.setString(4,addr3) ;
					p.setString(5,city) ;
					p.setString(6,state) ;
					p.setString(7,country) ;
					p.setString(8,pincode) ;
					p.setString(9,ph1) ;
					p.setString(10,ph2) ;
					p.setString(11,email) ;


						int x = p.executeUpdate() ;

						if(x > 0)
			 System.out.println("Record Updated Successfully");


	}





	ResultSet getVendorDetails() throws Exception// to get all vendors details.........
	{


		String sql = "select * from vendor" ;

		PreparedStatement p = cc.getStatement(sql)  ;

		return p.executeQuery() ;

	}




	ResultSet getVendorDetails(int id) throws Exception // to get details of particular vendor....
		{

			String sql = "select * from vendor where v_id =?" ;

			PreparedStatement p = cc.getStatement(sql) ;
			p.setInt(1,id);

			return p.executeQuery() ;

	}

}